public class Hotel {
    //酒店类Hotel，内含成员变量room和guests，room为Room类二维数组，行表示楼层数，列表示房间数;guests为Guest类数组，存储住户信息
    Room[][] room;
    //无参构造方法，设置酒店初始值为八楼，每层楼七个房间
    Hotel(){
        room = new Room[8][7];
        //利用setHotel方法创建酒店的房间，方便代码复用
        setHotel();
    }
    //有参构造方法，通过传入参数来确定酒店楼层数与房间数
    Hotel(int floor,int roomNumber){
        room = new Room[floor][roomNumber];
        setHotel();
    }
    //setHotel方法，用于初始化酒店
    private void setHotel() {
        for (int i = 0;i < room.length;i++){
            for (int j = 0;j <room[i].length;j++){
                room[i][j] = new Room((i+1)*1000+(j+1));
            }
        }
    }
    //办理入住方法
    public void residentIn(int roomNumber,String name,int idNumber){
        int floor = roomNumber/1000,number = roomNumber%1000;
        if (room[floor-1][number-1].resident.name == null){
            Guest resident = new Guest(name,idNumber);
            room[floor-1][number-1].resident = resident;
            resident.residentRoomNumber = roomNumber;
            System.out.println("入住成功！");
        }else {
            System.out.println("该房间有人，请重新输入in，再次办理入住！");
        }
    }
    //办理退房方法
    public void residentOut(int roomNumber){
        int floor = roomNumber/1000,number = roomNumber%1000;
        if (room[floor-1][number-1].resident.name == null){
            System.out.println("该房间没有顾客入住！");
        }else {
            room[floor-1][number-1].resident = null;
            System.out.println("退房成功！");
        }
    }
    //查询酒店入住情况方法
    public void show(){
        for (Room[] f : room){
            for (Room r : f){
                System.out.print(r.roomNumber+" ");
            }
            System.out.println();
            for (Room r : f){
                if (r.resident != null){
                    System.out.print(r.resident.name+" ");
                }else {
                    System.out.print(r.resident+" ");
                }
            }
            System.out.println();
        }
    }
    //房间类Room
    class Room{
        //成员变量，包含房间号和住户姓名
        int roomNumber;
        Guest resident;
        //创建房间的构造方法，设置房间的门牌号
        Room(int roomNumber){
            this.roomNumber = roomNumber;
        }
    }
    //用户类Guest
    class Guest{
        //成员变量，包含身份证号，姓名，以及入住房间号
        int idNumber,residentRoomNumber;
        String name;
        Guest(){}
        Guest(String name,int idNumber){
            this.name = name;
            this.idNumber = idNumber;
        }
    }
}